<?php


namespace app\queue\stomp;


use common\service\DelayOrderTaskStepCategoryConfirmService;
use app\queue\BaseConsumer;
use Exception;
use Webman\Stomp\RetryAbleConsumer;

/**
 * 延期单任务确认状态检查
 * Class DelayOrderConfirmedCheckConsumer
 * @package app\queue\redis
 */
class DelayOrderTaskConfirmStatusCheckConsumer extends BaseConsumer implements RetryAbleConsumer
{
    // 要消费的队列名
    public $queue = 'delay_order_task_confirm_status_check';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * run
     * @param $data
     * @throws Exception
     */
    public function doConsume($data)
    {
        DelayOrderTaskStepCategoryConfirmService::getInstance()->delayOrderTaskConfirmStatusCheck($data['delay_order_task_id_list']);
    }

    /**
     * 重试间隔
     * @return int
     */
    public function getTtr()
    {
        return 10;
    }

    /**
     * 重试检查
     * @param $attempt
     * @param $error
     * @return bool
     */
    public function canRetry($attempt, $error)
    {
        trace(format_exception_info($error), 'ERR');
        return $attempt <= 3;
    }
}
